package com.gzbsoft.sc.common.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

import static cn.hutool.core.collection.CollUtil.newArrayList;
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台API")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gzbsoft.sc.modules.sys.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }
    @Bean
    public Docket createWebApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("web API")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gzbsoft.sc.modules.app.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("工之宝")
                .description("工之宝后台api接口")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }
    private List<ApiKey> security() {
        return newArrayList(
                new ApiKey("token", "token", "header")
        );
    }
}
